// pages/detail/detail.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    create_time:"",
    text:"",
    title:"",
    id:0,
    noteid:0,
    uid:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    that.setData({
      create_time: options.create_time,
      text: options.text,
      id: options.id,
      noteid: options.noteid,
      uid: options.uid,
      title: options.title
    })
    wx.showLoading({
      title: '加载中',
      mask: true
    })
    setTimeout(function () {
      that.setData({
        create_time: options.create_time,
        text: options.text,
        id: options.id,
        noteid: options.noteid,
        uid: options.uid,
        title: options.title
      })
      wx.hideLoading();
    }, 1000)
    console.log(that.data.text)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  deleteRecord: function(e){
    var that = this
    wx.showModal({
      title: '提示',
      content: '确定要删除吗？',
      success: function (sm) {
        if (sm.confirm) {
          wx.request({
            url: `${app.globalData.apiurl}api/index/deleteNote`,
            method: 'POST',
            data: {
              uid: app.globalData.userInfo.uid,
              noteid: that.data.noteid
            },
            success: res => {
              console.log(that.data.id)
              //判断用户手记内容是否为空
              var page = getCurrentPages();
              var prevpage = page[page.length - 2];
              prevpage.setData({
                needDelete: that.data.id
              })
              wx.showToast({
                title: '删除成功！',
                icon: "none"
              })
              setTimeout(function () {
                wx.switchTab({
                  url: '/pages/note/note',
                })
              }, 700)
            }
          })
        } 
        else if (sm.cancel) {
          console.log('用户点击取消')
        }
      }
    })
   
  }
})